#ifndef __EMV_API_H__
#define __EMV_API_H__

#include "interface.h"
#include "devapi.h"
#include "txn_par.h"
#include "platform.h"
#include "apitrans.h"
#include "result.h"

#define SINGLE_TLVOBJ       0x01    /* it is a single constructed object */
#define STRING_TLVOBJ       0x02    /* it is a tlv object string not coded in a constructed object */
#define DECODE_LEVEL1       0x10    /* just decode the object in level one */

#define SEARCH_ALL_DESC     0x01    /* search all the descendants */
#define SEARCH_ONLY_SON     0x02    /* search only its sons  */


extern emv_fun_t * pemv;

extern int timeouts_test( uint32_t timeout  );
extern void timeouts_start( uint32_t start_time );
extern int debug_aux_hex( char *title,uint8_t * data, int dataLen );
extern int get_keys( int secs );
extern int _nv_read(uint32_t offset, uint8_t * buf, int buflen);
extern int _nv_write(uint32_t offset, uint8_t * buf, int buflen);
extern int _bcd_2_asc(uint8_t * bcd, int asclen, uint8_t * asc, int align);
extern int _asc_2_bcd(uint8_t * ascstr, int asclen, uint8_t * bcdstr, int align);
extern int _get_transamt(uint8_t trans_type, uint64_t * cash, uint64_t * cashback);
extern int sprint_hex( uint8_t *str, char *dataTitle,  uint8_t *data, int dataLen );
extern uint64_t _bcd_2_uint64( uint8_t *bcd,  int bcd_len );
extern int emv_rf_poll( int timeout );
extern int emv_icc_powerdown();
extern int read_card(void);
extern int _get_pinentry_test(int type, publickey_t *pin_key, uint8_t * result ,uint8_t * choose_mode);
extern int save_emv_water(uint8_t *buffer, int len);
extern int _lcd_msg(char * title, uint8_t * msg, int len,  int yesno, int waittime);
extern void sha1(unsigned char * inbuf, int inlen, unsigned char * digest);
extern int get_emv_log(int type);
extern int _iss_ref(uint8_t * pan, int panlen);
extern int _acctype_sel(void);
extern int rsa_recover(uint8_t *pin, publickey_t * pkey, uint8_t * pout);
extern void rand_vector(unsigned char * ranvec, int len);
extern void get_datetime(unsigned char * buf);
extern int emv_ec_switch( void );
extern int _sm2_verify_sig( sm2_verify_t *data, sm2_pubkey_t *pubkey );
extern void _sm3( uint8_t *in, int32_t len, uint8_t *out );
extern int emv_icc_powerup();
extern int emv_icc_rw(unsigned char *inbuf, int inlen,
                        unsigned char *outbuf, int olen);
extern unsigned int _c4_2_uint(uint8_t * c4);
extern void _uint_2_c4(unsigned int num, uint8_t * c4);
extern uint64_t _bcd_2_uint64( uint8_t *bcd,  int bcd_len );
extern int _inc_tsc(void);
extern int _lcd_msg(char * title, uint8_t * msg, int len,  int yesno, int waittime);
extern int _acctype_sel(void);
extern int _iss_ref(uint8_t * pan, int panlen);
extern int _candidate_sel(emv_candidate_t * pcan, int amt, int times);
extern int _cert_confirm(uint8_t type, uint8_t * pcon, int len);

extern int init_emv_inf(void);
extern int init_emv_files(int kernel);
extern int get_ec_balance(int mode);
extern int get_log_fmt( int pos_entry_type,int log_type,uint8_t *rec_num,uint8_t *fmtLen,uint8_t* fmtbuf);
extern int get_log_data( int pos_entry_type,int log_type,uint8_t rec_num,uint8_t *logLen,uint8_t* logbuf);
extern int go_online(unsigned char * buff, int len, unsigned char * resp);
extern int update_capk(void);

#endif
